
/**
 * 字符串工具类
 */
class StringUtil{
 static HEAD_SLOGAN="快乐星球!!!啦啦啦，啦啦拉，我是快乐的小画家";
    /**
     * 字符格式化
     */
static format(){
    if( arguments.length == 0 )
        return null;

    var str = arguments[0];
    for(var i=1;i<arguments.length;i++) {
        var re = new RegExp('\\{' + (i-1) + '\\}','gm');
        str = str.replace(re, arguments[i]);
    }
    return str;
}
//生成uuid
static uuid() {
	var s = [];
	var hexDigits = "0123456789abcdef";
	for (var i = 0; i < 36; i++) {
		s[i] = hexDigits.substr(Math.floor(Math.random() * 0x10), 1);
	}
	s[14] = "4"; // bits 12-15 of the time_hi_and_version field to 0010
	s[19] = hexDigits.substr((s[19] & 0x3) | 0x8, 1); // bits 6-7 of the clock_seq_hi_and_reserved to 01
	s[8] = s[13] = s[18] = s[23] = "-";

	var uuid = s.join("");
	return uuid;
}


//警告信息
static warning(val){

    return {
      title:'警告',
      message:val,
      type:'warning'
    };
}

  /**
   * 成功信息
   * @param val
   * @returns {{title: string, message: *, type: string}}
   */
  static success(val){

    return {
      title:'成功',
      message:val,
      type:'success'
    };
  }
/**
 * 检查空值
 * https://blog.csdn.net/qq_38666502/article/details/82904861
 * @param {} val
 * @param {*} mes
 */
static  checkNull(val){
    if(val == null || !val || val == undefined   ){
        return true;
    }
    return false;

}
/**
 * 查询localStorage
 */
static  getCaseArray(){
    let temp = localStorage.getItem("caseArray");
    let caseArray = temp ? JSON.parse(temp) : [];
    return caseArray;
}

  /**
   * 替换
   * @param str
   * @param oldPattern
   * @param newPattern
   * @returns {*|void|string|*}
   */
  static replace(str,oldPattern,newPattern){
    if(this.checkNull(str)){
      return str;
    }
    while (str.indexOf(oldPattern) != -1){
      str = str.replace(oldPattern,newPattern);
    }
    return str;

}

 static joinURL(prefixURL, str){
   if(this.checkNull(str)){
     return "";
   }
   let joinURLS = "";
  let imgs =   str.split("&&");
   for(let i  = 0 ;i<imgs.length;i++){
     if(i!=0){
       joinURLS += "<br>"
     }
     if(this.checkNull(imgs[i])){
       continue;
     }

    let url = prefixURL + this.replace(imgs[i],"" +
      "\\","/");
     joinURLS += "<img src='"
     +url
     +"'/>"

   }
   return joinURLS;

}



}
// let img = "files\\image\\2020\\11\\dashuju(-53193462).jpg&&files\\image\\2020\\11\\dp(1411812507).jpg&&files\\image\\2020\\11\\elastic(1115605547).jpg";
// console.log(img.split("&&").length)
// let str = "files\\image\\2020\\11\\ap1(-939011404).jpg";
// console.log(StringUtil.replace(str,"\\","/"));
// console.log(StringUtil.joinURL(img))
export {StringUtil};
